import java.util.Arrays;

public class MyStack2<E> {
    public Object[] elem;
    public int usedSize;

    public MyStack2(){
        this.elem=new Object[10];
    }
    public void push(E val){
        if (isFull()){
            elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize-1]=val;
        usedSize++;
    }
    public boolean isFull(){
        return usedSize==elem.length;
    }
    public E pop(){
        if (isEmpty()){
            return null;
        }
        E oldVal=(E)elem[usedSize-1];
        usedSize--;
        return oldVal;
    }

    public E  peek(){
        if (isEmpty()){
            return null;
        }
        return (E)elem[usedSize-1];
    }
    public boolean isEmpty(){
        return usedSize==0;
    }
}
